define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var userId = 0;
    var Controller = {
        index: function () {
            userId = $('#userId').val();
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/assistantorder/index' + location.search  + '&uid='+userId,
                    // add_url: 'user/assistantorder/add',
                    // edit_url: 'user/assistantorder/edit',
                    // del_url: 'user/assistantorder/del',
                    // multi_url: 'user/assistantorder/multi',
                    // import_url: 'user/assistantorder/import',
                    table: 'user_assistant_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'assistant.nickname', title: __('Assistant.nickname'), operate: 'LIKE'},
                        {field: 'assistant_id', title: __('Assistant_id')},
                        {field: 'order', title: __('Order'), operate: 'LIKE'},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'discount_amount', title: '优惠金额'},
                        {field: 'distance_amount', title: '路费'},
                        {field: 'real_amount', title: '订单总额'},
                        {field: 'amount', title: '助教费'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
                        {field: 'pay_status', title: __('Pay_status'), searchList: {"0":__('Pay_status 0'),"1":__('Pay_status 1'),"2":__('Pay_status 2')}, formatter: Table.api.formatter.status},
                        {field: 'order_start_time', title: __('Order_start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order_end_time', title: __('Order_end_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'server_start_time', title: __('Server_start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'server_end_time', title: __('Server_end_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'delete', title: __('Delete'), searchList: {"0":__('Delete 0'),"1":__('Delete 1')}, formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
